/* rcsoisa1.p - Propogate number change through the work_abs_mstr             */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.5 $                                                         */
/*V8:ConvertMode=NoConvert                                                    */
/* REVISION: 9.0      CREATED: 01/19/99      BY: *M05Q* Seema Varma           */
/* REVISION: 9.0     MODIFIED: 03/13/99      BY: *M0BD* Alfred Tan            */
/* REVISION: 9.0     MODIFIED: 04/28/99      BY: *J3BM* Reetu Kapoor          */
/* REVISION: 9.1     MODIFIED: 08/12/00      BY: *N0KP* Mark Brown            */
/* $Revision: 1.5 $    BY: Jean Miller       DATE: 03/22/01  ECO: *P008*      */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

{mfdeclre.i}

/* INPUT PARAMETERS */
define input parameter l_shpfrom   like abs_shipfrom no-undo.
define input parameter l_abs_id    like abs_id       no-undo.
define input parameter i_new       like abs_id       no-undo.

/* TEMP TABLES */

define temp-table t_done no-undo
   field t_shipfrom like abs_shipfrom
   field t_abs_id like abs_id
index t_abs_id is primary unique
   t_shipfrom t_abs_id.

{rcwabsdf.i}

/* MAIN PROCEDURE BODY */
run ip_convert_id
   (input l_shpfrom,
    input l_abs_id,
    input i_new).

/* END OF MAIN PROCEDURE BODY */

/* INTERNAL PROCEDURES */

PROCEDURE ip_convert_id:
/*--------------------------------------------------------------------
   Purpose:     Recursively change a shipper number in the work_abs_mstr
   Parameters:
   Notes:
----------------------------------------------------------------------*/
   /* INPUT PARAMETERS */
   define input parameter l_shpfrom like abs_mstr.abs_shipfrom no-undo.
   define input parameter l_abs_id  like abs_mstr.abs_id       no-undo.
   define input parameter i_new     like abs_mstr.abs_id       no-undo.

   /* BUFFERS */
   define buffer b2_abs_mstr for work_abs_mstr.

   /* PROCEDURE BODY */

   /* MAKE SURE THIS RECORD WASN'T ALREADY PROCESSED, */
   /* IN CASE OF CORRUPT CIRCULAR STRUCTURES          */
   if can-find (t_done where
                t_shipfrom = l_shpfrom and
                t_abs_id   = l_abs_id )
   then
      return.

   /* FLAG THAT THIS RECORD IS PROCESSED */
   create t_done.
   assign
      t_shipfrom = l_shpfrom
      t_abs_id   = l_abs_id.

   if recid(t_done) = -1 then .

   if can-find (first work_abs_mstr
                where abs_shipfrom = l_shpfrom
                  and abs_id       = l_abs_id)
   then do:

      /* PROPOGATE CHANGE TO CHILDREN OF SHIPPER */
      for each b2_abs_mstr where
            abs_shipfrom = l_shpfrom and
            abs_par_id   = l_abs_id
      exclusive-lock:

         if abs_par_id = substring(abs_id,2,length(abs_par_id)) then
         run ip_convert_id
            (input abs_shipfrom,
             input abs_id ,
             input substring(abs_id,1,1) + i_new +
                   substring(abs_id,length(abs_par_id) + 2)).

         abs_par_id = i_new.

      end.  /* FOR EACH WORK_ABS_MSTR */

   end.  /* IF CAN-FIND(WORK_ABS_MSTR......) */

   /* UPDATE THE CURRENT RECORD */
   find first work_abs_mstr where
      abs_shipfrom = l_shpfrom and
      abs_id       = l_abs_id
   exclusive-lock no-error.

   if available work_abs_mstr then
      abs_id = i_new.

END PROCEDURE.  /* IP_CONVERT_ID */
